package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlTransient;
import valueObject.CategoryVO;
import valueObject.CourseVO;

/**
 *
 * @author David
 */
@Entity
@Table(name = "category")
@NamedQueries({
    @NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c")})
public class Category implements Serializable, JPAEntity<CategoryVO> {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idCategory")
    private Integer idCategory;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "categoryidCategory")
    private Collection<Course> courseCollection;

    public Category() {
    }

    public Category(Integer idCategory) {
        this.idCategory = idCategory;
    }

    public Category(Integer idCategory, String name) {
        this.idCategory = idCategory;
        this.name = name;
    }

    public Integer getIdCategory() {
        return idCategory;
    }

    public void setIdCategory(Integer idCategory) {
        this.idCategory = idCategory;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public Collection<Course> getCourseCollection() {
        return courseCollection;
    }

    public void setCourseCollection(Collection<Course> courseCollection) {
        this.courseCollection = courseCollection;
    }

    @Override
    public CategoryVO toValueObject() {
        CategoryVO categoryVO = new CategoryVO();
        categoryVO.setId(idCategory);
        categoryVO.setName(name);
        ArrayList<CourseVO> courseVOs = new ArrayList<CourseVO>();
        /*if(courseCollection != null){
            for(Course c : courseCollection){
                courseVOs.add(c.toValueObject());
            }
        }*/
        categoryVO.setCourses(courseVOs);
        return categoryVO;
    }
    
}